import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;

import javax.swing.JTextField;

public class SearchScreen extends Screen
{	
	Screen currScreen, currSidebar;
	Screen defaultScreen, highlightScreen;
	Screen sidebarScreen;
	
	private BrikPanel panelHandle;
	
	public SearchScreen(BrikPanel _handle)
	{
		// Call parent
		super("imgs/top_s1.png");
		
		panelHandle = _handle;
		
		defaultScreen = new Screen("imgs/search_screen_s1.png");
		highlightScreen = new Screen("imgs/map_route_s4.png");
		sidebarScreen = new Screen("imgs/map_route_menu2_s1.png");

		defaultScreen.setPosition(129, 88);
		highlightScreen.setPosition(222, 88);
		sidebarScreen.setPosition(129, 88);
		
		currScreen = defaultScreen;
		currSidebar = null;
		
		// Define hotspots
		highlightScreen.addHotspot(new Hotspot(135, 135, 235, 235, null));
		highlightScreen.addHotspot(new Hotspot(469, 112, 469 + 120, 112 + 115, null));
	}
	
	public void reset()
	{
		currScreen = defaultScreen;
		currSidebar = null;
	}
	
	public void doSearch(String s)
	{
		currScreen = highlightScreen;
		currSidebar = sidebarScreen;
		panelHandle.hideSearchBox();
	}
	
	@Override
	public void draw(Graphics g)
	{
		g.drawImage(bg, 129, 0, null);
		currScreen.draw(g);
		if (currSidebar != null)
		{
			currSidebar.draw(g);
		}
	}
	
	@Override
	public void checkClick(int x, int y)
	{
		if (currScreen == highlightScreen)
		{
			if (highlightScreen.getHotspots().get(0).contains(x, y))
			{
				// Clicked back
				currScreen = defaultScreen;
				currSidebar = null;
				panelHandle.showSearchBox();
			}
			else if (highlightScreen.getHotspots().get(1).contains(x, y))
			{
				// Clicked map
				currScreen = defaultScreen;
				currSidebar = null;
				panelHandle.showSearchBox();
				panelHandle.searchToMap();
			}
		}
	}
}